<?php

require_once('../tcpdf/tcpdf.php');
require_once('../tcpdf/config/lang/eng.php');
include_once ('../datos/AccesoDatos.php');
require_once ('../genericos/translate.php');

class MYPDF extends TCPDF {

    //Page header
    public function Header() {
        // Logo
        $image_file = K_PATH_IMAGES . 'logo_example.jpg';
        $this->Image($image_file, 10, 10, 15, '', 'JPG', '', 'T', false, 300, '', false, false, 0, false, false, false);
        // Set font
        $this->SetFont('helvetica', 'B', 20);
        // Title
        $this->Cell(0, 15, '<< TCPDF Example 003 >>', 0, false, 'C', 0, '', 0, false, 'M', 'M');
    }

}

// extend TCPF with custom functions
// create new PDF document
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Nicola Asuni');
$pdf->SetTitle('TCPDF Example 006');
$pdf->SetSubject('TCPDF Tutorial');
$pdf->SetKeywords('TCPDF, PDF, example, test, guide');

// set default header data
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, '', '');

// set header and footer fonts
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));

//$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));

$pdf->setPrintFooter(false);
// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

//set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);

//set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);

//set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);

//set some language-dependent strings
$pdf->setLanguageArray($l);

// ---------------------------------------------------------
// set font
$pdf->SetFont('helvetica', '', 12);

// add a page
$pdf->AddPage();



(int) $i = 0;
$centroMedico;
$paciente;
$medico;
$cuerpoCitas;

if (isset($_GET['print'])) {
    $id = base64_decode($_GET['print']);
    $sql = "traerDatosxCitaPaquete('" . $id;
    $objDatos = new AccesoDatos();
    $objDatos->ejecutarConsulta($sql);
    while ($row = $objDatos->devuelveArreglo()) {
        if ($i == 0) {
            $centroMedico = $row['centro'];
            $paciente = $row['paciente'];
            $medico = $row['medico'];
            $fecha = split("-", $row['fecha']);
            $fecha = $fecha[2] . "-" . $fecha[1] . "-" . $fecha[0];
            $cuerpoCitas = '<tr><td>' . $fecha . '</td><td>' . $row['inicio'] . '</td><td>' . $row['final'] . '</td></tr>';
        } else {
            $fecha = split("-", $row['fecha']);
            $fecha = $fecha[2] . "-" . $fecha[1] . "-" . $fecha[0];
            $cuerpoCitas .= '<tr><td>' . $fecha . '</td><td>' . $row['inicio'] . '</td><td>' . $row['final'] . '</td></tr>';
        }
        $i++;
    }
}


// create some HTML content
$html = "<html><head>";

$html .= "<style>
table {
width:100%;
border-top:1px solid #e5eff8;
border-right:1px solid #e5eff8;
margin:1em auto;
border-collapse:collapse;
}
td {
color:#575757;
border-bottom:1px solid #e5eff8;
border-left:1px solid #e5eff8;
padding:.3em 1em;
text-align:center;
}
h4{
margin: 10px 10px;
}
</style>";
$html .= "</head><body>";
$html .= '<p>' . _("centroMedico") . ': ' . $centroMedico . '</p>';
$html .= '<p>' . _("empleado") . ': ' . $medico . '</p>';
$html .= '<p>' . _("paciente") . ': ' . $paciente . '</p>';
$html .= '<h4>' . _("listaCitasAsignadas") . '</h4>';
$html .= '<table>';
$html .= '<tr><td bgcolor="#ccc">' . _("fechaCita") . '</td><td bgcolor="#ccc">' . _("inicioCita") . '</td><td bgcolor="#ccc">' . _("finalCita") . '</td></tr>';
$html .= $cuerpoCitas;
$html .= '</table>';
$html;
$html .= "</body></html>";
// output the HTML content
$pdf->writeHTML($html, true, false, true, false, '');


// reset pointer to the last page
$pdf->lastPage();

// ---------------------------------------------------------
//Close and output PDF document
sleep(1);
$pdf->Output('citas.pdf', 'I');
